package com.ddwl.user.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.user.TrackBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.user.TrackVo;
import com.ddwl.user.service.TrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Fu Zhaohui
 * @version 1.0.0
 * @date 2021/6/1 10:03
 */
@Api(tags = "活动轨迹")
@Auth(product = {BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.IOT})
@RequestMapping("/track")
@RestController
@RequiredArgsConstructor
public class TrackController extends BaseController {

    private final TrackService trackService;

    @ApiOperation("上传活动轨迹")
    @PostMapping("upload")
    public RestVo<Boolean> upload(@Valid @RequestBody TrackBo bo) {
        bo.setOperator(getUserId());
        trackService.upload(bo);
        return RestVo.ok(null);
    }

    @ApiOperation("查看设备活动轨迹")
    @PostMapping("device")
    public RestVo<List<TrackVo>> device(@RequestParam String mac) {
        return RestVo.ok(trackService.device(mac));
    }
}
